<%@page import="java.util.regex.Pattern"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="java.util.*"%>
<%@ page import="cn.pzhuweb.pojo.SUser" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>判断数据合法性</title>
</head>
<body>
<%
	HashMap<String, SUser> map = null;
	if (application.getAttribute("MAP") != null) {
		map = (HashMap<String, SUser>) application.getAttribute("MAP");
	} else {
		map = new HashMap<String, SUser>();
	}
%>
<%
	request.setCharacterEncoding("UTF-8");
	String xm = request.getParameter("xm");
	String sage = request.getParameter("age");
	String[] hobby = request.getParameterValues("hobby");
%>
欢迎<%=xm%>登录，你的登录信息如下：
<br> 姓名：<%=xm%><br> 年龄：<%=sage%><br> 爱好：<%=Arrays.toString(hobby)%><br>
<h1>正在处理，请稍后......</h1>
<%
	if (xm == "") {
		session.setAttribute("error", "noxm");
		response.sendRedirect("error.jsp");
		return;
	}
	Integer age = 0;
	try {
		age = Integer.parseInt(sage);
	} catch (Exception e) {
		session.setAttribute("error", "agewr");
		response.sendRedirect("error.jsp");
		return;
	}
	if (hobby.length == 0) {
		session.setAttribute("error", "nohobby");
		response.sendRedirect("error.jsp");
		return;
	}
%>

<%
	/* if (!map.containsKey(xm)) {
        map.put(xm, xm);
        application.setAttribute("xm", xm);
        application.setAttribute("age", age);
        application.setAttribute("hobby", Arrays.toString(hobby));
        response.sendRedirect("show.jsp");
        } else{
            session.setAttribute("error", "exist");
            response.sendRedirect("error.jsp");
            return;
        }*/

	if (map.containsKey(xm)) {
		session.setAttribute("error", "exist");
		response.setHeader("refresh", "1;url='error.jsp'");
		return;
	}
	SUser user = new SUser(xm, age, hobby);
	map.put(xm, user);
	session.setAttribute("user", xm);
	application.setAttribute("MAP", map);
	response.setHeader("refresh", "2;url='show.jsp'");
%>
</body>
</html>